package com.inossem.warehousemanage_tv.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.inossem.warehousemanage_tv.MainActivity;
import com.orhanobut.logger.Logger;
import com.yatoooon.screenadaptation.ScreenAdapterTools;

/**
 * BaseFragment
 *
 * @author 詹建宇
 * @time on 2018/12/4 20:11
 * @email jianyu.zhan@inossem.com
 */
public abstract class BaseFragment extends Fragment {
    public MainActivity mActivity;
    public View mView;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mActivity = (MainActivity) context;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(initLayout(), container, false);
        ScreenAdapterTools.getInstance().loadView(mView);
        return mView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
        initClick();
    }

    @Override
    public void onResume() {
        super.onResume();
        Logger.i("当前页面 Fragment ClassName【" + this.getClass().getName() + "】");
    }

    //==============================================================================================

    /**
     * 设置布局
     *
     * @return layout id
     */
    public abstract int initLayout();

    /**
     * 初始化布局
     */
    public abstract void initView();

    /**
     * 设置数据
     */
    public abstract void initData();

    /**
     * 设置点击事件
     */
    public abstract void initClick();

}
